package com.szmirren.vxApi.spi.handler.impl;

import com.google.common.collect.Maps;
import com.szmirren.vxApi.core.common.mq.RocketMQProducer;
import com.szmirren.vxApi.core.entity.VxApis;
import com.szmirren.vxApi.spi.handler.VxApiBeforeHandler;
import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * 前置处理器处理示例
 *
 * @author <a href="http://szmirren.com">Mirren</a>
 */
public class TestBeforeHandlerSimple implements VxApiBeforeHandler {
    private static final Logger LOG = LogManager.getLogger(TestBeforeHandlerSimple.class);
    private VxApis apis;

    @Override
    public void handle(RoutingContext event) {
        // 这里做些什么事情后将请求放行到下一个处理器,或者在这里响应请求
        LOG.info("beforeHandler : " + apis);

        Map<String, Object> dataMap = Maps.newHashMapWithExpectedSize(2);
        dataMap.put("apis", apis);
        dataMap.put("bodyData", event.request().params());
        //将api信息发送到队列
        RocketMQProducer.sendMsg(dataMap.toString());

        event.next();
    }

    public TestBeforeHandlerSimple(VxApis api) {
        super();
        this.apis = api;
    }

}
